package com.ruoyi.web.handl;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.service.ISysUserService;
import io.swagger.models.auth.In;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpSession;
import java.util.Date;

@Component
public class MyHandle implements MetaObjectHandler {
    @Autowired
    private HttpSession session;
    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject,"createTime", Date.class,new Date());
        long x = ((SysUser)session.getAttribute("userName")).getUserId();
        int y = (int)x;
        Integer z = y;
        this.strictInsertFill(metaObject,"sysCreateUserId",Integer.class,z);
        this.strictInsertFill(metaObject,"sysRkUserId",Integer.class,z);
        this.strictInsertFill(metaObject,"sysCkUserId",Integer.class,z);
        this.strictInsertFill(metaObject,"rkTime",Date.class,new Date());
        this.strictInsertFill(metaObject,"ckTime",Date.class,new Date());

        //this.strictInsertFill(metaObject,"sysCreateUserId",Integer.class,z);
        this.strictInsertFill(metaObject,"purTime",Date.class,new Date());
        this.strictInsertFill(metaObject,"checkTime",Date.class,new Date());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject,"checkTime",Date.class,new Date());
        this.strictUpdateFill(metaObject,"rkTime",Date.class,new Date());
        this.strictUpdateFill(metaObject,"ckTime",Date.class,new Date());
    }
}
